/*
 * GTK VNC Widget
 *
 * Copyright (C) 2006  Anthony Liguori <anthony@codemonkey.ws>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.0 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 */

#ifndef _COROUTINE_H_
#define _COROUTINE_H_

#include "config.h"

#if WITH_UCONTEXT
#include "continuation.h"
#elif WITH_WINFIBER
#include <windows.h>
#else
#include <glib.h>
#endif

typedef void *(thread_entry)(void *);

struct thread_data
{
    thread_entry* entry;
    void* data;
};

struct lock_and_cond
{
    GCond *run_cond;
    GMutex *run_lock;
    GCond *socket_cond;
    GMutex *socket_lock;
    GCond *condition_cond;
    GMutex *condition_lock;
    guint wait_id;
    guint condition_id;
    gboolean run_notified;
    gboolean socket_notified;
    gboolean condition_notified;
    gboolean pending_wakeup;
    gboolean run_cancelled;
};

GThread* coroutine_init(thread_entry* entry, void* data, int channel_type);

gboolean coroutine_is_main(GThread* thread);

struct lock_and_cond* coroutine_get_lac(GThread *thread);

static inline gboolean coroutine_self_is_main(void) {
    return coroutine_is_main(g_thread_self());
}

#endif
/*
 * Local variables:
 *  c-indent-level: 8
 *  c-basic-offset: 8
 *  tab-width: 8
 * End:
 */
